package com.dao;

import com.entity.News;
import org.apache.ibatis.annotations.*;
import java.util.List;


/**
 * @Description: 新闻dao  // 类说明，在创建类时要填写
 * @ClassName: NewsDao    // 类名，会自动填充
 * @Author: weisn          // 创建者
 * @Date: 2020/12/9 10:21   // 时间
 * @Version: 1.0     // 版本
 */
public interface NewsDao {

    /**
     * 添加账户
     */
    @Insert("insert into wenyu_news(cover,name,context,time,wy_class)"+"values(#{cover},#{name},#{context},now(),#{wy_class})")
    @SelectKey(keyProperty = "id" , statement = "SELECT LAST_INSERT_ID()",before = false,resultType = Integer.class)
    boolean NewsInsert(News news);


    /**
     * 查询媒体新闻
     * @return
     */
    @Select("select count(*) from wenyu_news where class=1")
    public int selectCountClass();

    /**
     * 查询所有
     * @return
     */
    @Select("select * from wenyu_news order by id asc limit #{begin},#{size}")
    public List<News> selectList(@Param("begin")int begin,@Param("size")int size );

    /**
     * 删除账户
     * @param id
     * @return
     */
    @Update("delete from wenyu_news where id=#{id}")
    boolean newslistupdate(int id);

    /**
     * 通过id查找
     * @param id
     * @return
     */
    @Select("select * from wenyu_news where id=#{id}")
    public News select(int id);

    /**
     * 自增重置
     */
    @Update("ALTER TABLE wenyu_news AUTO_INCREMENT = 1" )
    public boolean alter();

    /**
     * 修改
     */
    @Update("update wenyu_news set cover=#{cover},name=#{name},context=#{context},time=now(),wy_class=#{wy_class} where id=#{id}")
    boolean update(News news);

    /**
     * 查询总数
     * @return
     */
    @Select("select count(*) from wenyu_news ")
    int getNewsCount();

//    /**
//     * 升序查询
//     */
//    @Select("select * from wenyu_news")
//    public List<News> selectNews();
}
